﻿<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%--@include file="../header.jsp"--%>
<%
String user = "";
if ( request.getSession().getAttribute("userName") != null)
	user = (String)request.getSession().getAttribute("userName");
else 
	response.sendRedirect("index.action");
String contextPath = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>上传文件</title>
<script>

	function closeWindows(flag){
		if (flag==0)
			window.close();
		else{
			/*window.returnValue="http://img1.cache.netease.com/cnews/2010/8/28/201008280949097650f.jpg";*/
			window.returnValue = document.getElementById("returnValue").value; 
		//	alert( window.returnValue );
			window.close();
		} 
		
	}
	function diplayMsg(){
		document.getElementById("msg").innerHTML = "<font color=red>请等待，正在上传...</font>";
	}
 	function callback(msg) {
 		document.getElementById("file").outerHTML = document.getElementById("file").outerHTML;
	 	if ( msg.indexOf("success") !=-1){
 		 	var begin = msg.indexOf("|");
 	 		var path = msg.substring(begin+1,msg.length);
 	 		document.getElementById("returnValue").value= path;
 	 		msg = msg.substring(0,begin);
		}	
 		document.getElementById("msg").innerHTML = "<font color=red>"+msg+"</font>";
 	}
</script>
 
<style type=text/css>
.perview {width:600px;background:#fff;font-size:12px; border-collapse:collapse;}
.perview td, .perview th {padding:5px;border:1px solid #ccc;}
.perview th {background-color:#f0f0f0; height:20px;}
.perview a:link, .perview a:visited, .perview a:hover, .perview a:active {color:#00F;}
.perview table{ width:100%;border-collapse:collapse;}

</style>
</head>

<body>
<!-- <form action="uploadFile.action" id="form1" name="form1" encType="multipart/form-data" method="post" target="hidden_frame" >-->
<form action="dealUpload.jsp" id="form1" name="form1" encType="multipart/form-data" method="post" target="hidden_frame" > 
<table border="0" class="perview">
	<tr>
			<th>选择文件</th>
<!-- 		<th width="60%">预览图</th>  -->	
		</tr>
		<tr>
			<td height="200">
				<input id="file" name="file" type="file" />
				<input type="hidden"  name="returnValue"  id="returnValue"/>
				<input type="hidden"  name="uploadFolder" id="uploadFolder" value=""/>
				<INPUT type="submit" value="上传文件" onclick="diplayMsg()"/><br/>
				<span id="msg"></span>
				<br/>							
				<iframe name='hidden_frame' id="hidden_frame" 	style='display:none'></iframe>
			</td>
			<!-- 
			<td align="center"></td>
			 -->
		</tr>
		<tr><td colspan="2">
		<input type="button" value="确定" onclick="closeWindows(1)" />&nbsp; 
		<input type="button" value="取消" onclick="closeWindows(0)" />
		</td></tr>
</table>
</form>
 
</body>
    <script>
	function getQueryString(name)
	{
		// 如果链接没有参数，或者链接中不存在我们要获取的参数，直接返回空
		if(location.href.indexOf("?")==-1 || location.href.indexOf(name+'=')==-1)
		{
			return '';	
		}
		// 获取链接中参数部分
		var queryString = location.href.substring(location.href.indexOf("?")+1);	
		// 分离参数对 ?key=value&key2=value2
		var parameters = queryString.split("&");	
		var pos, paraName, paraValue;
		for(var i=0; i<parameters.length; i++){
				// 获取等号位置
				pos = parameters[i].indexOf('=');	
				if(pos == -1) { continue; }	
				// 获取name 和 value	
				paraName = parameters[i].substring(0, pos);	
				paraValue = parameters[i].substring(pos + 1);
				// 如果查询的name等于当前name，就返回当前值，同时，将链接中的+号还原成空格
				if(paraName == name){
					return unescape(paraValue.replace(/\+/g, " "));
				}	
		}
		return '';
	};
	document.getElementById("uploadFolder").value=getQueryString('uploadFolder');
</script>
</html>
